<template>
    <Card>
        <div>
            <div class="contract-detial-btns">
                <Button type="primary" @click="back">返回</Button>
                <template v-if="!isReadOnly&&!this.pageParams.readOnly">
                    <Button type="primary" @click="submit">提交</Button>
                </template>
            </div>
        </div>
        <Collapse v-model="openPanel">
            <Panel name="1" v-if="isApprove || pageParams.processStatus === 'approved'">
                日志
                <div class="content" slot="content">
                    <approveHistory :Obj="Obj"/>
                </div>
            </Panel>
            <Panel name="2">
                基本信息
                <div class="content" slot="content">
                    <BaseInfo ref="baseInfo" :formData="pageInfo"/>
                </div>
            </Panel>
            <Panel name="3">
                合同信息
                <div class="content" slot="content">
                    <contractInfo :Obj="Obj" :readOnly="readOnly" @getChildData="getChildData"/>
                </div>
            </Panel>
            <Panel name="4">
                金融产品
                <div class="content" slot="content">
                    <FinanceInfo :Obj="Obj"/>
                </div>
            </Panel>
            <Panel name="5">
                业务办理
                <div class="content" slot="content">
                    <Business
                        ref="business"
                        :Obj="Obj"
                        :pageParams="pageInfo"
                        :dataDict="dataDict"
                        :isApprove="isApprove"
                        @submitDataFn="submitDataFn"
                        @closeSpin="closeSpin"
                    />
                </div>
            </Panel>
        </Collapse>
    </Card>
</template>
<script>
    import {
        submitChange
    } from "_p/basic/api/contract/post-loan-info-change/change-repayment";

    // 日志
    import approveHistory from "_p/basic/pages/contract/common/approve-history/approve-history";
    // 金融产品
    import FinanceInfo from "_p/basic/pages/contract/common/finance-info/finance-info";
    // 业务办理
    import Business from "_p/basic/pages/contract/post-loan-info-change/change-repayment-date-detial/Business";
    // 合同信息
    import contractInfo from "_p/basic/pages/contract/common/contract-info/contract-info";
    // 基本信息
    import BaseInfo from "_p/basic/pages/contract/common/base-info";

    export default {
        components: {
            approveHistory,
            FinanceInfo,
            contractInfo,
            BaseInfo,
            Business
        },
        props: {
            Obj: {
                //caseNo, contractNo, roleType
                type: Object,
                required: true
            },
            spinShow: {
                type: Boolean,
                required: true
            },
            // 是否是供应商
            isSP: {
                type: Boolean,
                required: true
            },
            //是否是审批页面
            isApprove: {
                type: Boolean,
                required: true
            },
            //是否 审批完成
            isApproved: {
                type: Boolean,
                required: true
            },
            isReadOnly: {
                type: Boolean,
                default: false
            },
            pageParams: {
                type: Object,
                required: true
            },
            //合同号
            contractNo: {
                type: String,
                required: true
            },
            dataDict: {
                type: Object
            },
            userInfo: {
                type: Object,
                required: true
            },
            businessSource: {
                type: String,
                required: true
            },
            roleType: {
                type: Array,
                required: true
            }
        },
        data() {
            return {
                openPanel: [2, 3, 4, 5],
                type: null,
                readOnly: null,
                caseNo: null,
                loading: true,
                pageInfo: this.pageParams
            };
        },

        mounted() {
            this.init();
        },
        methods: {
            init() {
                if (this.$refs.baseInfo) {
                    this.$refs.baseInfo.formData = Object.assign(
                        {},
                        this.$refs.baseInfo.formData,
                        this.pageInfo
                    );
                }
            },
            submit() {
                this.$Modal.confirm({
                    title: "确认提交？",
                    onOk: () => {
                        if (this.$refs.business) {
                            this.showSpin();
                            this.$refs.business.formValidate("submitDataFn");
                        }
                    }
                });
            },
            //提交 请求
            submitDataFn(data) {
                if (!data) return;
                let d = Object.assign({businessSource: this.businessSource}, this.pageInfo, data);
                submitChange(d)
                    .then(res => {
                        this.$emit("closeSpin");
                        if (res.code === "0000") {
                            this.$Message.success("提交成功!");
                            this.back();
                        }
                    })
                    .catch(e => {
                        this.$emit("closeSpin");
                    });
            },
            getChildData(data) {
                if (data.phone)
                    this.Obj.phone = data.phone;
            },
            showSpin() {
                this.$emit("showSpin");
            },
            closeSpin() {
                this.$emit("closeSpin");
            },
            back() {
                this.$emit("back");
            }
        }
    };
</script>
